/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.service.processor.rule;

import cn.hutool.core.util.ObjectUtil;
import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.fee.core.domain.Fee;
import info.peigen.hotpot.business.fee.core.service.processor.base.AbstractFeeServiceProcessor;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(FeeRuleCompleteProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/9/9
 */
@SuppressWarnings("rawtypes")
@Component
public class FeeRuleCompleteProcessor extends AbstractFeeServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 89;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        Fee     fee     = (Fee) serviceContext.getDomain();
        Account account = (Account) serviceContext.getExtend().get("account");
        if (ObjectUtil.isNull(fee.getChargeAccount()) && ObjectUtil.isNotNull(account)) {
            fee.setChargeAccount(account);
            fee.getFeeLog().setAccount(account);
        }
    }
}
